package client;

import java.net.MalformedURLException;
import java.rmi.*;

import server.*;
import client.InvestComPost_GUI;
import client.ApplySuc_GUI;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.naming.ConfigurationException;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Font;

public class EnterInvestCom_GUI extends JFrame {
	public static int ComID;

	private JPanel contentPane;

	/**
	 * Launch the application.
	 *//*
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					EnterInvestCom_GUI frame = new EnterInvestCom_GUI(ComID);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public EnterInvestCom_GUI(int id) {
		ComID = id;
		setTitle("\u6295\u8D44\u516C\u53F8");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		JLabel lblNewLabel = new JLabel(
				"欢迎来到本投资公司！！");
		lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 18));
		lblNewLabel.setBounds(53, 10, 248, 39);
		contentPane.add(lblNewLabel);
		try {

			final Person per = new Person();
			final int pid=per.getPID();
			Configuration config = new Configuration();
			String rmiAddress = config.getRmiAddress();
			final StaffInterface SI = (StaffInterface) Naming.lookup(rmiAddress
					+ "Staff");
			final PersonInterface PI = (PersonInterface) Naming
					.lookup(rmiAddress + "Person");
			final CompanyInterface CI = (CompanyInterface) Naming
					.lookup(rmiAddress + "Company");

			if (PI.getComID(pid) == 0)

			{
				JButton btnNewButton = new JButton("应聘");
				btnNewButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						try {
							if (PI.setComID(pid, ComID) && PI.apply(pid,SI.getPost(ComID, 1))) {
								int staffNum = CI.getStaffNum(pid);
								if (CI.setStaffNum(ComID, staffNum + 1)) {
									ApplySuc_GUI investapplysuc = new ApplySuc_GUI();
									investapplysuc.setLocationRelativeTo(null);
									investapplysuc.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
									investapplysuc.setVisible(true);
									dispose();
								}
							}
						} catch (Exception e1) {
							e1.printStackTrace();
						}
					}
				});
				btnNewButton.setBounds(159, 90, 120, 40);
				contentPane.add(btnNewButton);

			} else {
				if (PI.getComID(pid) == ComID) {
					JButton button = new JButton("\u8FDB\u5165\u516C\u53F8");
					button.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent e) {
							InvestComPost_GUI investcompost;
							try {
								investcompost = new InvestComPost_GUI();
								investcompost.setLocationRelativeTo(null);
								investcompost
										.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
								investcompost.setVisible(true);
								dispose();
							} catch (ConfigurationException e1) {

								e1.printStackTrace();
							} catch (RemoteException e1) {

								e1.printStackTrace();
							} catch (MalformedURLException e1) {

								e1.printStackTrace();
							} catch (NotBoundException e1) {

								e1.printStackTrace();
							}

						}
					});
					button.setBounds(159, 130, 120, 40);
					contentPane.add(button);

				} else {
					JOptionPane.showMessageDialog(null, "You have had a job!");

				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		JButton button_1 = new JButton("\u79BB\u5F00\u516C\u53F8");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
		button_1.setBounds(159, 170, 120, 40);
		contentPane.add(button_1);

	}
}
